package cn.kgc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.mapper.TccRecordMapper;
import cn.kgc.entity.TccRecord;
import cn.kgc.service.TccRecordService;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;

/**
 * @author k
 */
@Slf4j
@Service("tccRecordService")
@SuppressWarnings("all")
public class TccRecordServiceImpl extends ServiceImpl<TccRecordMapper, TccRecord> implements TccRecordService {
    @Override
    public boolean hasTry(String xid, String branchId) {
        return getBaseMapper().selectCount(
                    new LambdaQueryWrapper<>(TccRecord.class)
                        .eq(TccRecord::getXid, xid)
                        .eq(TccRecord::getBranchId, branchId)
                        .eq(TccRecord::getStatus, 1)
                )>0;
    }
    @Override
    public boolean hasCommit(String xid, String branchId) {
        return getBaseMapper().selectCount(
                    new LambdaQueryWrapper<>(TccRecord.class)
                        .eq(TccRecord::getXid, xid)
                        .eq(TccRecord::getBranchId, branchId)
                        .eq(TccRecord::getStatus, 2)
                )>0;
    }
    @Override
    public boolean hasCancel(String xid, String branchId) {
        return getBaseMapper().selectCount(
                        new LambdaQueryWrapper<>(TccRecord.class)
                                .eq(TccRecord::getXid, xid)
                                .eq(TccRecord::getBranchId, branchId)
                                .eq(TccRecord::getStatus, 3)
                )>0;
    }
}